package com.stone;

import java.io.File;
import java.time.LocalDate;
import java.time.Period;
import java.time.ZoneId;
import java.util.Date;
import java.util.HashMap;

/**
 * 时间相减
 */
public class TimeDateUtils {

    public static void main(String[] args) {

//        Date date1 = new Date();
//        Date date2 = new Date();
//
//        System.out.println((date1.getTime() - date2.getTime()) / (24 * 60 * 60 * 1000) + "天");
//
//        LocalDate dateTime1 = date1.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
//        LocalDate dateTime2 = date2.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
//        Period between = Period.between(dateTime1, dateTime2);
//        System.out.println(between.getDays());



        // File file = new File("F:\\huanan\\biz.zhgl\\yxkc.api\\src\\main\\resources\\template\\月考察处级以下表模板.xls");
        // System.out.println(file);

        // int[] height = new int[3];
        // height[0]=3;
        // height[1]=2;
        // height[2]=3;
        //
        // maxArea(height);


        int ssfswwraexaaf = Substring("ssfswwraexaaf");
        System.out.println(ssfswwraexaaf);

    }
    public static int Substring(String s) {
        if (s.length()==0) return 0;
        HashMap<Character, Integer> map = new HashMap<Character, Integer>();
        int max = 0;
        int left = 0;
        for(int i = 0; i < s.length(); i ++){
            if(map.containsKey(s.charAt(i))){
                left = Math.max(left,map.get(s.charAt(i)) + 1);
            }
            map.put(s.charAt(i),i);
            max = Math.max(max,i-left+1);
        }
        return max;

    }


        public static int lengthOfLongestSubstring(String s) {
            // 记录字符上一次出现的位置
            int[] last = new int[128];
            for(int i = 0; i < 128; i++) {
                last[i] = -1;
            }
            System.out.println(last);
            int n = s.length();

            int res = 0;
            int start = 0; // 窗口开始位置
            for(int i = 0; i < n; i++) {
                System.out.println("i:"+i);
                int index = s.charAt(i);
                System.out.println("index:"+last[index]);
                start = Math.max(start, last[index] + 1);
                res   = Math.max(res, i - start + 1);
                last[index] = i;

                System.out.println("**********");
            }

            return res;
        }


    public static int maxArea(int[] height) {
        int l = 0, r = height.length - 1;
        int ans = 0;
        while (l < r) {

            System.out.println("********");
            int area = Math.min(height[l], height[r]) * (r - l);
            System.out.println("height[l]:"+height[l]+"height[r]:"+height[r]+"(r - l)"+(r - l)+"area:"+area);
            ans = Math.max(ans, area);
            if (height[l] <= height[r]) {  // 移动较小的那一端
                ++l;
            }
            else {
                --r;
            }
        }
        return ans;
    }
}
